#ifndef NOTE_H
#define NOTE_H

#include <QString>
#include <QDateTime>
#include <QVector>
#include <QTextEdit>
#include "ndb.h"
#include <QObject>
#include <QPushButton>
#include <QLabel>
#include <QMessageBox>

struct Note
{

    int m_id=-1;
    int m_taskId=-1;
    QString m_text;
    QDateTime m_datetime;

    Note(QString text="");
    Note(int id, int taskId, QString text, QDateTime datetime);
};

using NoteList = QVector<Note>;

class Notes: public QObject
{
    Q_OBJECT
public:

    NoteList *m_pnote_list=nullptr;
    QTextEdit *m_pnote_edit=nullptr;
    QPushButton *m_front_btn=nullptr;
    QPushButton *m_next_btn=nullptr;
    QPushButton *m_save_btn=nullptr;
    QLabel *m_note_edit_time=nullptr;
    QLabel *m_note_page=nullptr;

    int m_taskId=-1;

    Notes(QTextEdit *note_edit, QPushButton *front_btn, QPushButton *next_btn, QPushButton *save_btn,QLabel *note_edit_time, QLabel *note_page, QObject *parent=nullptr);

    bool getNotes(int taskId);

    void showNote();
    void showNote(const Note &note);
    void showNote(int index);

    // 索引
    int getIndex() const {return m_index;}
    bool setIndex(int index);
    bool addIndex();
    bool reduceIndex();
    bool isLast() const {return m_index >= m_pnote_list->size()-1;}


    bool nextNote();

    bool createNoteAndUpdateIndex(int taskId);
    bool updateNote(Note &note);
    bool deleteNoteFromListIndex(int index);

    void update(int taskId);


    void textChanged_slot();
    void frontClick_slot();
    void nextClick_slot();
    void saveClick_slot();

private:
    int m_index;    // 当前笔记的索引


};



#endif // NOTE_H
